﻿using System.Data;

namespace DBMock.Validators
{
    /// <summary>
    /// 相等验证器
    /// </summary>
    public class EqualValidator : Validator
    {
        /// <summary>
        /// 相等列
        /// </summary>
        public string RefColumn { get; set; }

        /// <summary>
        /// 初始化EqualValidator
        /// </summary>
        /// <param name="refColumn"></param>
        public EqualValidator(string refColumn)
        {
            RefColumn = refColumn;
        }

        public override object Validate(object value, Strategy strategy, Builder[] group, DataRow row)
        {
            if (string.IsNullOrEmpty(RefColumn) || !row.Table.Columns.Contains(RefColumn))
                return value;

            return row.Field<object>(RefColumn);
        }
    }
}
